<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>18 继承-原型继承</title>
</head>

<body>
  <script>
    function Parent() {
      this.x = 100;
    }
    Parent.prototype.getX = function () {
      console.log(this.x)
    }

    function Child() {
      this.y = 100;
    }
    Child.prototype.getY = function () {
      console.log(this.y)
    }

    /**
     * copyExtend 拷贝继承
     * @param {*} Child 子类 
     * @param {*} Parent 父类
     */
    function copyExtend(Child, Parent) {
      let child_proto = Child.prototype,
        parent_proto = Parent.prototype;
      for (const key in Parent.prototype) {
        child_proto[key] = Parent.prototype[key]
      }
    }
    copyExtend(Child, Parent)

    let c1 = new Child();
    console.log(c1)
  </script>
</body>

</html>